package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.PackingDao;
import cn.itcast.dao.cargo.ShippingOrderDao;
import cn.itcast.domain.cargo.*;
import cn.itcast.service.cargo.ShippingControllerService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

@Service
public class ShippingControllerServiceImpl implements ShippingControllerService {

    @Autowired
    private ShippingOrderDao shippingOrderDao;
    @Autowired
    private PackingDao packingDao;

    @Override
    public PageInfo<ShippingOrder> findByPage(
            ShippingOrderExample shippingControllerExample, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ShippingOrder> list =shippingOrderDao.selectByExample(shippingControllerExample);
        return new PageInfo<>(list);
    }

    @Override
    public ShippingOrder findById(String id) {
        return shippingOrderDao.selectByPrimaryKey(id);
    }

    @Override
    public void delete(String id) {
        shippingOrderDao.deleteByPrimaryKey(id);
    }

    @Override
    public void save(ShippingOrder shippingOrder) {
/*        //1、设置委托单id，委托单状态为草稿为0
        shippingOrder.setId(UUID.randomUUID().toString());
        shippingOrder.setState(0);

        //获取装箱单id
        String packingIds = shippingOrder.getPackingIds();
        String[] array = packingIds.split(",");
        List<String> packingIdList = Arrays.asList(array);

        //2.根据装箱单id，获取装箱单；修改装箱单装态为已委托
        PackingExample packingExample = new PackingExample();
        packingDao.
        packingExample.createCriteria().andIdI(packingIdList);
//        packingExample.createCriteria().andId(packingIdList);
        List<Packing> packingList = packingDao.selectByExample(packingExample);
        if (packingIdList == null || packingIdList.size() == 0 ){
            throw  new RuntimeException("装箱单id为空");
        }
        //保存合同号
        String packingNos = "";
        //遍历购销合同
        for ( Packing packing :packingList) {
            packingNos = packing.getPackingListId();
        }
        shippingOrderDao.insertSelective(shippingOrder);*/
    }

    @Override
    public void update(ShippingOrder shippingOrder) {

    }
}
